#!/usr/bin/env python
#coding=utf-8

stack = []
def pushit():
	stack.append(raw_input(' Enter New String: ').strip()) # strip 移除字符串前后指定字符  ''

def popit():
	if len(stack) == 0:
		print 'Cannot pop from an empty stack!'
	else:
		print 'Removed [',`stack.pop()`,']'# `` 就是执行后 返回的字符串

def viewstack():
	print stack

CMDs = {'u':pushit, 'o':popit, 'v':viewstack} # 使用字典来访问对应的函数感觉很简洁

def showmenu():
	pr="""
p(U)sh
p(O)p
(V)iew
(Q)uit
Enter choice:"""
	while True:
		while True:
			try:
				choice = raw_input(pr).strip()[0].lower() # 将输入的字符小写
			except (EOFError,KeyboardInterrupt,IndexError) as e:
				choice = 'q'

			print '\nYou picked: [%s]' % choice
			if choice not in 'uovq':
				print 'Invalid option, try again'
			else:
				break

		if choice == 'q':
			break
		CMDs[choice]()

if __name__ == '__main__':
	showmenu()